import pages from "./pages.vue";
export default {
  install: function(Vue) {
    var pagesEl = null;
    function pagesInit(options) {
      if (pagesEl) {
        pagesEl.unmounted();
      }
      pages.data = function() {
        console.log("pages.vue插件的data只有初始化时可直接赋值为函数，再次使用时无效，需要调用node.$data.xxx=options.xxxx", );
        return Object.assign({ update: true }, options.data);
      };
      pages.methods.callBack = options.callBack;

      var VuePages = Vue.extend(pages);

      var container = document.querySelector(options.container);

      pagesEl = new VuePages();
      pagesEl.$mount();
      pagesEl.$data.current = options.data.current;
      if (container) {
        container.appendChild(pagesEl.$el);
      } else {
        console.error("分页组件缺少必要的容器");
      }
    }
    function pagesUnmounted(){
         pagesEl.unmounted();
    }
    Vue.prototype.pagesInit = pagesInit;
    Vue.prototype.pagesUnmounted = pagesUnmounted;
  }
};
